<?php

include_once 'Controller.php';
include_once 'models/Track.php';

class Track extends Controller {
  
  public function Track($attr=null){ 
    parent::__construct($attr);
    $this->model = new Track_($this->attributes);
  }
  
  public function add(){
  	//check the user input
    $this->checkInput('artist', 1);
    $this->checkInput('title',1);
    $this->checkInput('release',1);
    $this->checkInput('url');
    if ($this->fe->areThereErrors()){
      Proxy::send('<proxy id="response"><errorFields>'.$this->fe->getFormErrors().'</errorFields></proxy>');
    }
    else{
      if($this->attributes[mb_rel_id] == null) {//forced track insertion
        $this->attributes[artist] = $this->uword($this->attributes[artist]);
        $this->attributes[title] = $this->uword($this->attributes[title]);
      }
      return parent::add();
    }
  }
  
  public function get(){
  	return parent::get();
  }
  
  public function getFull(){
  	$this->error = false;
  	try {$this->result = $this->model->getFull();}
    catch(MTException $e){
      unset($this->result);
      $this->error = $e;
      throw $e;
    }
  }

}

?>
